package cn.z2huo.knowledge.concurrency.thinkinginjava.section_21_3.syncCodeBlock;

class DualSync implements Runnable {

    private final Object syncObject = new Object();

    @Override
    public void run() {
        this.f();
    }

    public synchronized void f() {
        for (int i = 0; i < 5; i++) {
            System.out.println("f()");
            Thread.yield();
        }
    }

    public void g() {
        synchronized (syncObject) {
            for (int i = 0; i < 5; i++) {
                System.out.println("g()");
                Thread.yield();
            }
        }
    }

}
